package student

import (
	"gin-project-01/gin-step04/gin17-mutli-tables/controllers"
	myModel "gin-project-01/gin-step04/gin17-mutli-tables/models"
	"github.com/gin-gonic/gin"
	"net/http"
	"strings"
)

type StudentController struct {
	controllers.BaseController //继承 controllers.BaseController
}

// List
//
//	@Description: http://localhost:8888/student/list/1 | http://localhost:8888/student/list/0
//	@receiver a
//	@param c
func (a StudentController) List(c *gin.Context) {
	all := c.Param("all")
	if strings.EqualFold(all, "1") {
		var studentDtoList []myModel.StudentDto
		myModel.Db.Preload("LessonList").Find(&studentDtoList)
		c.JSON(http.StatusOK, studentDtoList)
	} else {
		var studentList []myModel.Student
		myModel.Db.Find(&studentList)
		c.JSON(http.StatusOK, studentList)
	}

}
